# A tibble: 8 × 3
Region Company Sales
<chr> <chr> <dbl>
1 North Co.A 13
2 North Co.B 39
3 South Co.A 35
4 South Co.B 6
5 East Co.A 27
6 East Co.B 27
7 West Co.A 25
8 West Co.B 28
Zelazny Plots: Alternative Plotting with GGPlot
Welcome
This tutorial allows you to interactively explore R, writing and running code in directly your web browser. You’ll see above R is being set-up and loading packages right in this browser window.
This tutorial was created by Brennan Antone using WebR and Quarto. It adapts a classic exercise from: Zelazny, G. (1985). Say it with charts: the executive’s guide to visual communication. McGraw-Hill Education.
Introduction
In his classic exercise, Zalazny presented a simple data set comparing sales across for four regions for two companies: Company A and Company B. He asked participants to consider different ways of plotting the data, and what the implications of these approaches might be.
We will extend this exercise by using the ggplot2 package in R to demonstrate how different forms of visualizations can be implemented, alongside the dplyr and tidyr packages for data manipulation.
Challenge
Here is the example data, as presented in his figure:
It describes the sales of two companies, Company A and Company B, in June. The values show the percentage of each companies’ sales the originated from four regions: North, South, East, and West.
Readers are challenged to brainstorm different ways this could be converted to a chart, and then to consider the implications of choosing different types of charts on the message conveyed.
Data Setup
Running the code below, we can set up the data in a simple tibble.
This is a simple tibble with eight values. But is it “tidy data” based on Wickham definition?
Placing the data in the proper format for the type of plot you want is key when using ggplot. If we have eight “bars” we want to create, the simplest approach is to create a tibble with eight rows. Each case will then correspond to one bar. For instance, see the transformed data below:
How do we move from our original data to the new format? Using the pivot_longer command, we can make a tibble longer - meaning more rows and fewer columns.
We do this by specifying the columns we want to transform into additional rows, as well as how to rename the new columns in our tibble.
Different Plots
This same tibble can be used to generate many different possible configuration of plots. Zelazny created illustrations to show six of the many different possibilities:
Here is a template we can use for the basics of the plot. It sets up the basics without actually plotting any of the points.
Now, let’s get started on creating the actual plots in R!
Plot 1: Stacked Columns
Plot 2: Bar Charts
Plot 3: Ordered Bar Charts
Plot 4: Different Orders on Bars
Plot 5: Clustered Bar Charts
Plot 6: Pie Charts
This plot will be a little trickier. Adding coord_polar("y",start0) is a quick way to move from rectangular coordinates (e.g., bars) to polar coordinates (e.g. pie charts).
Takeaways
This tutorial has demonstrated that the same data can generate different types of visualizations.
The ggplot2 package, by using the Grammar of Graphics approach, provides you with flexibility to create different plots by combining different types of elements.